import time
import os
import operator

def ReadFullFile(filename):
	with open(filename) as f:
		content = f.read()
		f.close()
	return content

#try to parse a state from ACL2
#may raise a ValueError if the state is still being written
def ParseLifeLikeState(string, genno):
	coords = set()
	lines = string.split(",")
	for line in lines:
		coord = line.split(" ")
		if string != '\n' and string != '':
			try:
				x, y = coord
			except ValueError as e:
				print("Uh oh! Started reading a file before ACL2 finished writing it. This is okay, we'll just try again in a few ms.")
				raise e
			if x != '' and y != '':
				coords.add((int(x), int(y)))
	return coords

def ParseElementaryState(string, genno):
	coords = set()
	
	lines = string.split(",")
	for line in lines:
		coord = line.split(" ")
		if string != '\n' and string != '':
			try:
				x = coord[0]
			except ValueError as e:
				print("Uh oh! Started reading a file before ACL2 finished writing it. This is okay, we'll just try again in a few ms.")
				raise e
			if x != '':
				coords.add(int(x))
	return coords			
			
def DeleteFile(filename):
    os.remove(filename)
